import request from "../uni/request"
import { backend } from "../uni"

const userInfo = uni.getStorageSync("userInfo") || "{}"

export default {
	namespaced: true,
	state: {
		userInfo,
	},
	mutations: {
		setUserInfo(state, info) {
			state.userInfo = info
			uni.setStorageSync("userInfo", info)
		},
		logout(state) {
			state.userInfo = {}
			uni.removeStorageSync("userInfo")
			uni.removeStorageSync("token")
			uni.removeStorageSync("refreshToken")
		},
	},
	actions: {
		async getUserInfo({ state, commit }, reload = false) {
			if (!reload && state.userInfo.id) {
				return state.userInfo
			}
		},
	},
	getters: {
		isLogin(state) {
			return !!state.userInfo.id
		},
	},
}
